﻿using StoryTeller.Domain.Exceptions;
using StoryTeller.Domain.Repository;
using StoryTeller.Infrastructure.DataAccess.DAL;
using StoryTeller.Infrastructure.DataAccess.DAL.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StoryTeller.Repository
{
    public class ContributionRatingRepository: IContributionRatingRepository
    {
        public IContributionRatingDAL dal { get { return DALFactory.GetContributionRatingDAL(); } }

        public void Insert(Domain.ContributionRating entidade)
        {
            try
            {
                if (entidade.Validate())
                    throw new ValidationMessagesException(entidade.ValidationMessages);

                dal.Insert(entidade);
            }
            catch (ValidationMessagesException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new FriendlyErrorMessageException(Resources.Error.ErrorMessages.ContributionRatingInsertError, ex);
            }
        }

        public void Delete(int userId, int contributionId)
        {
            try
            {
                dal.Delete(userId, contributionId);
            }
            catch (Exception ex)
            {
                throw new FriendlyErrorMessageException(Resources.Error.ErrorMessages.ContributionRatingDeleteError, ex);
            }
        }

        public ICollection<Domain.ContributionRating> Select(int contributionId)
        {
            try
            {
                return dal.Select(contributionId);
            }
            catch (Exception ex)
            {
                throw new FriendlyErrorMessageException(Resources.Error.ErrorMessages.ContributionRatingSelectByContributionIdError, ex);
            }
        }
    }
}
